package com.why.jvm.hotspot.src.share.vm.oops;

import com.why.jvm.hotspot.src.share.vm.oops.constants.ConstantUtf8Info;
import lombok.Data;

import java.util.Arrays;

/**
 * @author xiaoTian
 * @date 2022/7/16
 * @Description:
 */
@Data
public class FieldInfo {

    private ConstantPool constantPool;

    private int accessFlags;

    private int nameIndex;

    private int descriptorIndex;

    private int attributesCount;

    private AttributeInfo[] attributeInfos;

    public void initAttributeInfo(){
        attributeInfos = new AttributeInfo[attributesCount];
    }

    public String getName(){
        return ((ConstantUtf8Info)constantPool.getConstantPoolMap().get(nameIndex)).getValue();
    }

    public String getDescriptor(){
        return ((ConstantUtf8Info)constantPool.getConstantPoolMap().get(descriptorIndex)).getValue();
    }

    @Override
    public String toString() {
        return "FieldInfo{" +
                "accessFlags=" + accessFlags +
                ", nameIndex=" + nameIndex +
                ", name=" + getName() +
                ", descriptorIndex=" + descriptorIndex +
                ", descriptor=" + getDescriptor() +
                ", attributesCount=" + attributesCount +
                ", attributeInfos=" + Arrays.toString(attributeInfos) +
                '}';
    }
}
